home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9599 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  56 lines

  1. Newsgroups: comp.lang.c
  2. Path: newshub.nosc.mil!news!herman
  3. From: herman@nosc.mil (John W. Herman)
  4. Subject: Re: Handling complex numbers...
  5. Message-ID: <1996Mar11.204246.7444@nosc.mil>
  6. Sender: news@nosc.mil
  7. Organization: NCCOSC RDT&E Division, San Diego, CA
  8. References: <4hi113$2i8k@mercury.cc.uottawa.ca> <larry_kearney-0803960747220001@amaryllisp1.appsig.com>
  9. Date: Mon, 11 Mar 1996 20:42:46 GMT
  10.  
  11. larry_kearney@appsig.com (Larry Kearney) writes:
  12.  
  13. >> Dear fellow netters,
  14. >> 
  15. >> Can someone kindly explain to me how to represent complex numbers in C?
  16. >> I am writing a numerical method program to calculate the area under
  17. >> a curve using Simpson's Rule.  The problem that I face right now is
  18. >> the representation of "i" (where i^2 = -1) in my C program.
  19. >> 
  20. >> Here's a simple example of what I mean:
  21. >>   
  22. >>   _b
  23. >>  |           
  24. >>  | exp(ix) dx 
  25. >> _|             
  26. >> a
  27. >> 
  28. >> 
  29. >> How do I implement this function exp(ix)?
  30. >> 
  31. >> I'm grateful for your help.
  32. >> 
  33. >> Charles Tran
  34. >> -- 
  35. >> Charles
  36.  
  37. >The C language is not terribly efficient when it comes to complex numbers.
  38. >You can represent a complex number as a struct, i.e.,
  39.  
  40. >typedef struct
  41. >{
  42. >   double re;  /* real part of the complex number */
  43. >   double im;  /* imaginary part of the complex number */
  44. >} complex;
  45.  
  46. >but the big problem is that the arithmetic operators don't know what to do
  47. >when presented with values that are structures. As a result, the
  48. >programmer is required to implement functions that perform that standard
  49. >operations and that take complex structs as arguments. For example,
  50.  
  51. >void AddComplex ( complex *a, complex *b, complex *c )
  52. *** Stuff deleted ***
  53.  
  54. There are also macros for these problems which generate more effecient code.
  55. These have been posted several times before.
  56.